//
//  JZNavgationController.swift
//  SwiftWeibo
//
//  Created by Stone on 16/12/2.
//  Copyright © 2016年 Stone. All rights reserved.
//

import UIKit

class JZNavgationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的NavBar
        navigationBar.isHidden = true
        
        
    }
    
     
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //如果是根控制器则不隐藏
        if childViewControllers.count > 0 {
            //隐藏底部的tabBar
            viewController.hidesBottomBarWhenPushed = true
            //判断控制器的类型
            if let vc = viewController as? JZBaseViewController {
                
                var title = "返回"
                
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                //取出navItem
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popAction), isBack: true)
        }
            
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    //返回到上一级
    @objc private func popAction() {
        popViewController(animated: true)
    }
    
}
